package com.sun.lib_demo;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.sun.lib_tag.TagAdapter;
import com.sun.lib_tag.TagFlowGroup;
import com.sun.lib_tag.TagFlowLayout;
import com.sun.lib_tag.TagView;

/*
 *
 * #                                                   #
 * #                       _oo0oo_                     #
 * #                      o8888888o                    #
 * #                      88" . "88                    #
 * #                      (| -_- |)                    #
 * #                      0\  =  /0                    #
 * #                    ___/`---'\___                  #
 * #                  .' \\|     |# '.                 #
 * #                 / \\|||  :  |||# \                #
 * #                / _||||| -:- |||||- \              #
 * #               |   | \\\  -  #/ |   |              #
 * #               | \_|  ''\---/''  |_/ |             #
 * #               \  .-\__  '-'  ___/-. /             #
 * #             ___'. .'  /--.--\  `. .'___           #
 * #          ."" '<  `.___\_<|>_/___.' >' "".         #
 * #         | | :  `- \`.;`\ _ /`;.`/ - ` : | |       #
 * #         \  \ `_.   \_ __\ /__ _/   .-` /  /       #
 * #     =====`-.____`.___ \_____/___.-`___.-'=====    #
 * #                       `=---='                     #
 * #     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   #
 * #                                                   #
 * #               佛祖保佑         永无BUG              #
 * #                                                   #
 */

/**
 * Created by SunXiquan- on 2021/12/19.
 */
public class TagFragment extends Fragment {

    private View root;

    public static TagFragment newInstance(int pos) {
        
        Bundle args = new Bundle();
        args.putInt("pos",pos);
        TagFragment fragment = new TagFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        root = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_tag, container, false);
        return root;
    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        TagFlowLayout tagFlowLayout = root.findViewById(R.id.tagLayout);
        tagFlowLayout.setAdapter(new TagAdapter<String>() {
            @Override
            public View getView(TagFlowGroup parent, int position, String str) {
                TextView textView = (TextView) LayoutInflater.from(parent.getContext()).inflate(R.layout.item_tag, parent, false);
                textView.setText(str);
                return textView;
            }
        });
        tagFlowLayout.getAdapter().setTags("1", "哈哈哈", "测试");
        tagFlowLayout.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
            @Override
            public void onTagClick(TagView view, int position, TagFlowLayout parent) {
                startActivity(new Intent(getActivity(), MainActivity.class));
            }
        });
    }
}
